<template>
  <div class="manage-ad">
      <!-- 广告投放 -->
      <div class="container">
        <div class="model-title text-overflow">广告投放</div>
        <div class="form-box">
           <el-form :model="adForm" ref="adForm" label-width="100px">
             <el-form-item label="标题">
               <el-input v-model="adForm.title" placeholder="请输入标题"></el-input>
             </el-form-item>
             <el-form-item label="广告链接">
               <el-input v-model="adForm.url" placeholder="请输入广告链接"></el-input>
             </el-form-item>
             <el-form-item label="图片id">
               <el-input v-model="adForm.id" placeholder="如果不做修改，此处即可不用输入，忽略就好"></el-input>
             </el-form-item>
             <el-form-item label="图片上传">
               <input class="form-input" type="file" ref="img_file">
             </el-form-item>
             <div style="text-align:center">
               <el-button type="danger" @click="submitUpate">提交</el-button>
             </div>
           </el-form>
          
        </div>
      </div>
  </div>
</template>

<script>
export default {
  name:'manage-ad',
  data () {
    return {
        adForm:{
          title:null,
          url:null,
          id:null,     
        }
    };
  },
  components: {},
  created() {
    // user/app/slideshow/query/brandid ？不知道干吗的接口 post  brand_id=xxx
  },
  mounted() {},
  methods: {
    submitUpate(){
        let image = this.$refs.img_file.files[0];
        debugger
        let token = sessionStorage.getItem(1);
        let url = `user/app/slideshow/add/`+ token;
        let params = new FormData();
        //  `title=${this.adForm.title}&url=${this.adForm.url}&image=${image}`;
        params.append('title',this.adForm.title);
        params.append('url',this.adForm.url);
        params.append('image',image);
        if(this.adForm.id){
          params.append('id',this.adForm.id);
        }
        this.$Http.post(url,params,{
          headers:{
            'Content-Type' :'multipart/form-data'
          }
        }).then(res=>{
          if(res.data.resp_code === "000000"){
            // 提交成功
          }
          this.$notify.info({
            title:"提示",
            message:res.data.resp_message || "成功"
          })
        }).catch(err=>{
          this.$notify.info({
            title:"出错",
            message:"请求修改出错"
          })
        })
    }
  }
}

</script>
<style scoped>
.form-box{
  padding: 20px;
}
.form-input{
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 32px;
    line-height: 32px;
    outline: 0;
    padding: 0 15px;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
}

</style>